package com.ruoyi.web.controller.depot;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.depot.PreWarehouse;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.depot.service.IPreWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 仓库列表Controller
 * 
 * @author ruoyi
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/depot/warehouse")
public class PreWarehouseController extends BaseController
{
    @Autowired
    private IPreWarehouseService preWarehouseService;

    /**
     * 查询仓库列表列表
     */
    @PreAuthorize("@ss.hasPermi('depot:warehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(PreWarehouse preWarehouse)
    {
        startPage();
        List<PreWarehouse> list = preWarehouseService.selectPreWarehouseList(preWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出仓库列表列表
     */
    @PreAuthorize("@ss.hasPermi('depot:warehouse:export')")
    @Log(title = "仓库列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PreWarehouse preWarehouse)
    {
        List<PreWarehouse> list = preWarehouseService.selectPreWarehouseList(preWarehouse);
        ExcelUtil<PreWarehouse> util = new ExcelUtil<PreWarehouse>(PreWarehouse.class);
        util.exportExcel(response, list, "仓库列表数据");
    }

    /**
     * 获取仓库列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('depot:warehouse:query')")
    @GetMapping(value = "/{warehouseId}")
    public AjaxResult getInfo(@PathVariable("warehouseId") Long warehouseId)
    {
        return success(preWarehouseService.selectPreWarehouseByWarehouseId(warehouseId));
    }

    /**
     * 新增仓库列表
     */
    @PreAuthorize("@ss.hasPermi('depot:warehouse:add')")
    @Log(title = "仓库列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PreWarehouse preWarehouse)
    {
        return toAjax(preWarehouseService.insertPreWarehouse(preWarehouse));
    }

    /**
     * 修改仓库列表
     */
    @PreAuthorize("@ss.hasPermi('depot:warehouse:edit')")
    @Log(title = "仓库列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PreWarehouse preWarehouse)
    {
        return toAjax(preWarehouseService.updatePreWarehouse(preWarehouse));
    }

    /**
     * 删除仓库列表
     */
    @PreAuthorize("@ss.hasPermi('depot:warehouse:remove')")
    @Log(title = "仓库列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warehouseIds}")
    public AjaxResult remove(@PathVariable Long[] warehouseIds)
    {
        return toAjax(preWarehouseService.deletePreWarehouseByWarehouseIds(warehouseIds));
    }
}
